package org.example.factory_method;

/**
 * @author Zhang Yu
 * @description: 工厂方法：定义一个用于创建对象的接口，让子类决定实例化哪一个类。Factory Method使一个类的实例化延迟到其子类。
 * @date 2024/5/14 10:17
 */
public class Test {

    public static void main(String[] args) {
        INumberFactory factory = INumberFactory.getFactory("INumberFactoryImpl");
        Number result = factory.parse("123.456");
        System.out.println("result = "+ result +",type of result is" + result.getClass());
        INumberFactory factory1 = INumberFactory.getFactory("INumberFactoryImpl2");
        Number result1 = factory1.parse("123.456");
        System.out.println("result1 = "+ result1 +",type of result1 is" + result1.getClass());
        /**
         * sout:
         * result = 123.456,type of result isclass java.lang.Double
         * result1 = 123.456,type of result1 isclass java.math.BigDecimal
         */
    }

}
